package cn.tomas.rabbit.demo;

import cn.tomas.TomasApplication;
import cn.tomas.rabbit.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author Mr.Still
 * @version 1.0.0
 * @date 2021-11-11 11:24
 **/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes= TomasApplication.class)
@EnableAutoConfiguration
@Slf4j
public class DirectProducer {

    @Autowired
    @Qualifier("jacksonRabbitTemplate")
    private RabbitTemplate rabbitTemplate;

    @Test
    public void fanoutProduct(){
        String routingKey = "";
        try {
            int i = 1 / 1;
            routingKey = "info";
            rabbitTemplate.convertAndSend("direct.order.exchange",routingKey,new UserDTO("admin","info","man"));
        } catch(Exception e) {
            e.printStackTrace();
            routingKey = "error";
            rabbitTemplate.convertAndSend("direct.order.exchange",routingKey,new UserDTO("admin","error","man"));
        }

    }
}
